import {Component, OnInit} from '@angular/core';
import {ListConZoneTypeComponent} from '../list-con-zone-type.component';
import {Zero3Option} from '../../../../../frame/enum/zero3-option';
import {ConZoneTypeCondition} from '../../con-zone-type.type';
import * as fa from '@fortawesome/free-solid-svg-icons';
import { Services } from 'src/app/frame/module/services';
import { ConZoneTemplateCondition } from '../../../con-zone-template/con-zone-template.type';
import { Zero3Enum } from 'src/app/frame/enum/zero3-enum';

@Component({
    selector: 'app-search-list-con-zone-type',
    templateUrl: './search-list-con-zone-type.component.html',
    styleUrls: ['./search-list-con-zone-type.component.css']
})
export class SearchListConZoneTypeComponent implements OnInit {

    // func = this.upper.func;

    zero3Option = Zero3Option;

    condition = new ConZoneTypeCondition();

    extend = {
        keyup: (event) => {
            // T-O-D-O 51 # err
            if (event.keyCode > 32 || event.keyCode === 8) {
                this.listConZoneType.func.list.click(event);
            }
        },
        condition: {
            upper: {
                type: '',
                icon: fa.faSearchPlus,
                nickname: '上级对象',
                value: () => {
                    return this.condition.upper;
                },
                keyup: (event) => {
                    this.condition.upper = event.target.value;
                    this.extend.keyup(event);
                }
            },
            serNum: {
                icon: fa.faPen,
                nickname: '编号',
                value: () => {
                    return this.condition.serNum;
                },
                keyup: (event) => {
                    this.condition.serNum = event.target.value;
                    this.extend.keyup(event);
                }
            },
            fkUpperZone: {
                items: [],
                icon: fa.faList,
                nickname: '上级专区',
                change: (event) => {
                    console.log(this.condition.fkUpperZoneList);
                }
            },
            fkZoneTemplate: {
                items: [],
                icon: fa.faList,
                nickname: '专区模板',
                change: (event) => {
                    console.log(this.condition.fkZoneTemplateList);
                }
            },
            enuPosition: {
                items: Zero3Option.CON_ZONE_TYPE_POSITION,
                icon: fa.faList,
                nickname: '专区位置',
                change: (event) => {
                    console.log(this.condition.enuPositionList);
                }
            },
            serAudit: {
                icon: fa.faList,
                nickname: '审核状态',
                // value: '',
                change: (event) => {
                    // this.condition.serAuditList = [];
                    // console.log(this.field.serAudit.value);
                    // this.condition.serAuditList = this.field.serAudit.value.split(',');
                    console.log(this.condition.serAuditList);
                }
            },
            creator: {
                icon: fa.faUserAlt,
                nickname: '创建者',
                value: () => {
                    return this.condition.creator;
                },
                keyup: (event) => {
                    this.condition.creator = event.target.value;
                    this.extend.keyup(event);
                }
            },
            createTime: {
                icon: fa.faCalendar,
                nickname: '创建时间',
                value: () => {
                    // return `${this.condition.createTimeOUTSET} - ${this.condition.createTimeFINISH}`;
                    return this.condition.createTime;
                },
                focus: (event) => {
                    const dataOF = event.target.value.toString().split(' ~ ');
                    this.condition.createTimeOUTSET = dataOF[0];
                    this.condition.createTimeFINISH = dataOF[1];
                    this.listConZoneType.func.list.click(event);
                },
                blur: (event) => {
                    this.extend.condition.createTime.focus(event);
                }
            },
            serMemo: {
                icon: fa.faPen,
                nickname: '备注',
                value: () => {
                    return this.condition.serMemo;
                },
                keyup: (event) => {
                    this.condition.serMemo = event.target.value;
                    this.extend.keyup(event);
                }
            },
            lastModifyTime: {
                icon: fa.faCalendar,
                nickname: '最后修改时间',
                value: () => {
                    return this.condition.lastModifyTime;
                },
                focus: (event) => {
                    const dataOF = event.target.value.toString().split(' ~ ');
                    this.condition.lastModifyTimeOUTSET = dataOF[0];
                    this.condition.lastModifyTimeFINISH = dataOF[1];
                    this.listConZoneType.func.list.click(event);
                },
                blur: (event) => {
                    this.extend.condition.lastModifyTime.focus(event);
                }
            },
            lastModifier: {
                icon: fa.faUserAlt,
                nickname: '最后修改者',
                value: () => {
                    return this.condition.lastModifier;
                },
                keyup: (event) => {
                    this.condition.lastModifier = event.target.value;
                    this.extend.keyup(event);
                }
            },
        },
    };

    constructor(public listConZoneType: ListConZoneTypeComponent) {
        listConZoneType.search = this;
    }

    ngOnInit() {
        //
        Services.conZoneType.list(new ConZoneTypeCondition({
            fkUpperZoneIsNull: Zero3Enum.YES
        }), {
            page: 0,
            size: 999,
            orders: 'createTime-desc,serNum-asc'
        }).subscribe(item => {
            console.log(item);
            if (item && item.code === 'success') {
                this.extend.condition.fkUpperZone.items = [];
                item.page.content.forEach(it => {
                    this.extend.condition.fkUpperZone.items.push({id: it.uuid, name: it.serName});
                });
            }
        });
        //
        Services.conZoneTemplate.list(new ConZoneTemplateCondition(), {
            page: 0,
            size: 999,
            orders: 'createTime-desc,serNum-asc'
        }).subscribe(item => {
            if (item && item.code === 'success') {
                this.extend.condition.fkZoneTemplate.items = [];
                item.page.content.forEach(it => {
                    this.extend.condition.fkZoneTemplate.items.push({id: it.uuid, name: it.serName});
                });
            }
        });
    }

}
